﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Clipping.Infrastructure.Models;
using System.Collections.ObjectModel;
using System.Windows.Media;
using Clipping.Utils;
namespace ClippingMaster
{
    public class NewsModel : GalaSoft.MvvmLight.ObservableObject
    {
        static Color openedColor = Colors.LightBlue;
        static Color uploadedColor = Colors.LightGreen;

        public NewsModel(News news,ISearchEngine searchEngine)
        {
            this.News = news;
            this.SearchEngine = searchEngine;
            if (news.HasSameNews && !news.SameNewsRetrived)
                this.hasUnretrivedSameNews = true;
            else
                this.hasUnretrivedSameNews = false;
        }

        public News News { get; private set; }


        private ObservableCollection<ClientInfo> _uploadedClients;
        public ObservableCollection<ClientInfo> UploadedClients
        {
            get { return _uploadedClients; }
            set
            {
                if (value == this._uploadedClients)
                    return;
                _uploadedClients = value;
                RaisePropertyChanged(() => this.UploadedClients);
                RaisePropertyChanged(() => this.Background);
            }
        }

        private bool _opened;
        public bool Opened
        {
            get { return _opened; }
            set
            {
                if (value == this._opened)
                    return;
                _opened = value;
                RaisePropertyChanged(() => this.Opened);
                RaisePropertyChanged(() => this.Background);
            }
        }


        private bool _isSelected;

        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                if (_isSelected == value)
                    return;
                _isSelected = value;
                RaisePropertyChanged(() => this.IsSelected);
            }
        }

        public  ISearchEngine SearchEngine { get; private set; }
      
        public Color Background
        {
            get 
            {
                if (UploadedClients != null && UploadedClients.Count > 0)
                    return uploadedColor;
                else if (Opened)
                    return openedColor;
                else
                    return Colors.Transparent;
            }
         
        }

        private bool hasUnretrivedSameNews;

        public bool HasUnretrivedSameNews
        {
            get { return hasUnretrivedSameNews; }
            set
            {
                if (this.hasUnretrivedSameNews == value)
                    return;
                hasUnretrivedSameNews = value;
                RaisePropertyChanged(() => this.HasUnretrivedSameNews);
            }
        }
    }
}
